// Note that this problem is not base conversion
// Sat Nov 27 20:32:10 GMT 2010

#include <iostream>
#include <string>
#include <sstream>
#include <stdio.h>

using namespace std;

int main()
{
	int n;
	scanf("%d\n", &n);

	for (int i = 0; i < n; i++) 
	{
		string s;
		getline(cin, s);

		if (s.find('R') != string::npos && 
		    s.find('C') != string::npos && 
		    ('0' <= s[1] && s[1] <= '9')) 
		{
			int r, c;
			char z;
			sscanf(s.c_str(), "%c%d%c%d", &z, &r, &z, &c);

	                string c_result = "";
			while (c > 0)
			{
				c_result.insert(c_result.begin(), 'A' + (c-1)%26);
				c = (c-1)/26;
			}
			cout << c_result << r << endl;
		}
		else
		{
			int r, c=0;
			while ('A' <= s[0] && s[0] <= 'Z')
			{
				c = c*26 + (s[0]-'A'+1);
				s.erase(0, 1);
			}
			stringstream ss(s);
			ss >> r;
			cout << 'R' << r << 'C' << c << endl;
		}
	}
	return 0;
}
